home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / utils / scrnsvrs / pyrosav3.lzh / savercnf.c < prev    next >
C/C++ Source or Header  |  1989-08-20  |  4KB  |  108 lines

  1. /*************************************************************************/
  2. /*   savercnf.c - Program to modify SAVER.PRG screen saver time value.   */
  3. /*                                                                       */
  4. /*   Mark A. Abreu   8/19/89     GEnie: M.ABREU                          */
  5. /*                                                                       */
  6. /*   This program reads SAVER.PRG and modifies the timer value in the    */
  7. /*   executable program.                                                 */
  8. /*                                                                       */
  9. /*   WARNING:  This program only works with the version of SAVER.PRG     */
  10. /*             I tested it on.  This will probably NOT work with         */
  11. /*             future versions of SAVER.PRG                              */
  12. /*                                                                       */
  13. /*   Created using SOZOBON C                                             */
  14. /*                                                                       */
  15. /*************************************************************************/
  16.  
  17. /*  Global include files  */
  18.  
  19. #include <osbind.h>
  20. #include <stdio.h>
  21. #include <errno.h>
  22. #include <portab.h>
  23.  
  24. #define TIMEPOS 886L     /*  location of timer in SAVER.PRG  */
  25. #define MINTIME 1        /*  minimum time in minutes         */
  26. #define MAXTIME 9        /*  maximum time in minutes         */
  27.  
  28. main()
  29. {
  30. WORD istat;              /*  status word  */
  31. WORD fh;                 /*  file handle  */
  32. WORD otimmili;           /*  old timmer millisecond value  */
  33. WORD oldmins;            /*  old time in minutes  */
  34. WORD ntimmili;           /*  new timer millisecond value  */
  35. WORD newmins;            /*  new time in minutes  */
  36. LONG lstat;              /*  status long word  */
  37. LONG charcntr;           /*  bytes read counter  */
  38.  
  39. /*
  40.   Open the file.
  41. */
  42.  
  43.    istat = Fopen("saver.prg",2);
  44.    if (istat <= 0)
  45.    {
  46.       switch (istat)
  47.       {
  48.          case EFILNF:
  49.               printf ("\r\nSAVER.PRG not found.  This configuration program");
  50.               printf ("\r\nand SAVER.PRG must be in the same directory.");
  51.               break;
  52.          case EACCDN:
  53.               printf ("\r\nSAVER.PRG could not be opened for WRITE access.");
  54.               printf ("\r\nCheck to see if SAVER.PRG is set READ-ONLY.");
  55.               break;
  56.          default:
  57.               printf ("\r\nOpen failure on SAVER.PRG, status = %d",istat);
  58.               break;
  59.       }
  60.       waitcr ("\r\nPress <Return> ");
  61.       Pterm(0);
  62.    }
  63.  
  64.    printf ("\r\nSAVER.PRG found and opened....");
  65.    
  66.    fh = istat;   /*  if status was positive then it's the file handle  */
  67.  
  68.    lstat = Fseek (TIMEPOS,fh,0);            /*  position to timer location */
  69.    charcntr = Fread (fh,2L,&otimmili);      /*  read timer value  */
  70.    oldmins = otimmili / 60 / 60;            /*  convert to minutes  */
  71.    printf ("\r\nScreen Saver time currently is %d minutes",oldmins);
  72.    printf ("\r\nEnter new value [%d to %d minutes]: ",MINTIME,MAXTIME);
  73.    scanf ("%1d",&newmins);                  /*  get new value  */
  74.    
  75. /*  make sure new value is within range  */
  76.  
  77.    if (newmins >= MINTIME && newmins <= MAXTIME)
  78.    {
  79.       ntimmili = newmins * 60 * 60;       /*  convert to milliseconds  */
  80.       lstat = Fseek (TIMEPOS,fh,0);       /*  position to timer location  */
  81.       lstat = Fwrite (fh,2L,&ntimmili);   /*  write timer value  */
  82.       if (lstat < 0)
  83.       {
  84.          printf ("\r\nWrite failure on SAVER.PRG, status = %ld",lstat);
  85.          waitcr ("  Press <Return> ");
  86.       }
  87.    }
  88.    else
  89.    {
  90.       printf ("\r\nInvalid entry.  SAVER.PRG unchanged.");
  91.       waitcr ("\r\nPress <Return> ");
  92.    }
  93.       
  94. /*
  95.   Close the file.
  96. */
  97.  
  98.   istat = Fclose (fh);
  99.   if (istat != 0)
  100.   {
  101.      printf ("\r\nCLOSE failure on SAVER.PRG, status = %d",istat);
  102.      waitcr ("   Press <Return> ");
  103.   }
  104.  
  105.   Pterm(0);
  106.  
  107. }
  108.